package com.dsbj.mp.icardservice.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dsbj.common.msg.ResponseMessage;
import com.dsbj.mp.icardservice.entity.Reservation;
import com.dsbj.mp.icardservice.entity.ReservationPrimary;
import com.dsbj.mp.icardservice.entity.SerialNumber;
import com.dsbj.mp.icardservice.mapper.ReservationMapper;
import com.dsbj.mp.icardservice.mapper.ReservationPrimaryMapper;
import com.dsbj.mp.icardservice.model.ReservationNoModel;
import com.dsbj.mp.icardservice.model.WorkflowFieldInfo;
import com.dsbj.mp.icardservice.service.asynctask.AsyncTask_submitReservationPrimary_toOA;
import com.dsbj.mp.icardservice.utils.Constants;
import com.dsbj.mp.icardservice.utils.DateUtils;
import com.dsbj.mp.icardservice.utils.PropertyUtil;
import com.dsbj.mp.icardservice.utils.strprocess.Time_convert;
import com.dsbj.mp.icardservice.webserviceclient.dsbjpmc.AllowUser;
import com.dsbj.mp.icardservice.webserviceclient.ecology.docimage.*;
import com.dsbj.mp.icardservice.webserviceclient.ecology.workflow.WorkflowService;
import com.dsbj.mp.icardservice.webserviceclient.ecology.workflow.WorkflowServicePortType;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.WriterException;
import com.google.zxing.common.BitMatrix;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.util.CollectionUtils;
import sun.misc.BASE64Decoder;

import javax.annotation.Resource;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URL;
import java.util.*;
import java.util.stream.Collectors;

@Service
public class ReservationService {

	private static Logger logger= LoggerFactory.getLogger(ReservationService.class);

	@Resource
	private ReservationMapper reservationMapper;

	@Resource
	private ReservationPrimaryMapper reservationPrimaryMapper;

	@Autowired
	private SerialNumberService serialNumberService;

	@Autowired
	private EcologyWebService ecologyWebService;

	@Autowired
	DataSourceTransactionManager dataSourceTransactionManager;

	@Autowired
	TransactionDefinition transactionDefinition;



	public List<Reservation> getAllRecords() {
		return reservationMapper.selectList(null);
	}

	/**
	 * @deprecated 测试方法。
	 * @param id
	 * @return
	 */
	public List<Reservation> getReservationById(String id) {

		List<Reservation> list = new ArrayList<>();
		list.add(reservationMapper.selectById(id));

		QueryWrapper<Reservation> queryWrapper = new QueryWrapper<>();
		queryWrapper.eq("id", id);
		list.add(reservationMapper.selectOne(queryWrapper));

		list.add(reservationMapper.selectOne(
				new QueryWrapper<Reservation>()
						.lambda()
						.eq(Reservation::getId, id)));

		list.add(reservationMapper.getById(id));
		list.add(reservationMapper.getByIdXml(id));
		list.add(reservationMapper.getByIdWrapper(new QueryWrapper<Reservation>().eq("id", id)));
		return list;
	}

	/**
	 * 获取新的(未被预约单引用的)预约单号。
	 *
	 * <pre>
	 *   tips: 该单号在预约单生成之前创建, 若此次预约单没有生成，则该单号可用于下一次的申请中。
	 *   该方法复杂，不简洁。
	 *   返回对象中同时提供二维码字符串。
	 * </pre>
	 * @param
	 * @return
	 * @author cjw 2019-09-25
	 */
	public ReservationNoModel getNewReservationno() {
		ReservationNoModel model = new ReservationNoModel();
		String dateStr = Time_convert.getCurrentTime_onlyDigit();
		String sn_searchstr = "reservation" + dateStr;
		SerialNumber serialNumber = serialNumberService.findBySerialNumber(sn_searchstr);

		/**
		 * 若serialNumber不为null,分析serialNumber中的信息,并获取“未被使用”的reservationno。
		 */
		String rno = null;
		if (null != serialNumber) {
			String resultA = serialNumber.getResultA();
			rno = dateStr + resultA;

			//分析该rno是否已被预约单引用
			boolean isExist=checkReservationno_isExist(rno);

			//若isExist为true，reservationno已存在,循环更新serialNumber, 直到生成的reservationno未被使用为止
			while (isExist){
				//调用存储过程,更新或创建对应的记录
				Map<String, Object> map_procedure = new HashMap<String, Object>();
				map_procedure.put("str2", "reservation" + dateStr);
				map_procedure.put("long2", 2);
				serialNumberService.p1(map_procedure);

				resultA=map_procedure.get("no1").toString();
				rno=dateStr+resultA;
				isExist=checkReservationno_isExist(rno);
			}
			model.setReservationno(rno);
			model.setQrCodeBase64Data(generateQrBase64(rno));
			return model;
		}else{
			/**
			 * 若serialNumber为null,直接创建serialNumber,并获得reservationno。
			 */
			//调用存储过程,更新或创建对应的记录
			Map<String, Object> map_procedure = new HashMap<String, Object>();
			map_procedure.put("str2", "reservation" + dateStr);
			map_procedure.put("long2", 2);
			serialNumberService.p1(map_procedure);

			String resultA=map_procedure.get("no1").toString();
			rno=dateStr+resultA;
			model.setReservationno(rno);
			model.setQrCodeBase64Data(generateQrBase64(rno));
			return model;
		}
	}

	public String generateQrBase64(String rno) {
		MultiFormatWriter multiFormatWriter = new MultiFormatWriter();
		Map hints = new HashMap();
		hints.put(EncodeHintType.CHARACTER_SET, "UTF-8"); //设置字符集编码类型
		hints.put(EncodeHintType.MARGIN, 1);  //设置白边
		BitMatrix bitMatrix = null;
		try {
			bitMatrix = multiFormatWriter.encode(rno, BarcodeFormat.QR_CODE, 200, 200,hints);
			BufferedImage image = toBufferedImage(bitMatrix);
			ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
			//输出二维码图片流
			try {
				ImageIO.write(image, "png",outputStream);
				return Base64.getEncoder().encodeToString(outputStream.toByteArray());
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		} catch (WriterException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		return null;
	}

	public static BufferedImage toBufferedImage(BitMatrix matrix) {
		int width = matrix.getWidth();
		int height = matrix.getHeight();
		BufferedImage image = new BufferedImage(width, height,
				BufferedImage.TYPE_INT_RGB);
		for (int x = 0; x < width; x++) {
			for (int y = 0; y < height; y++) {
				image.setRGB(x, y, matrix.get(x, y) ? 0xFF000000 : 0xFFFFFFFF);//0xFF000000黑；0xFFFFFFFF白
			}
		}
		return image;
	}

	/**
	 * 分析该reservationno是否存在。
	 * @param
	 * @return
	 * @author cjw 2019-09-25
	 */
	public boolean checkReservationno_isExist(String reservationno) {
		QueryWrapper<ReservationPrimary> queryWrapper=new QueryWrapper<>();
		queryWrapper.eq("RESERVATIONNO",reservationno);
		List<ReservationPrimary> reservations=reservationPrimaryMapper.selectList(queryWrapper);

		if(reservations.size()==0){
			return false;
		}else{
			return true;
		}
	}

	/**
	 * 该方法中含有"将预约单提交至OA端的逻辑"，其耗时不确定。
	 *
	 * @param user
	 * @param reservationPrimary
	 * @return
	 */
	public ResponseMessage save(AllowUser user, ReservationPrimary reservationPrimary) {
		TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition);
		//根据登陆人工号OA查找部门
		ReservationPrimary rpy = getByCreateUserEmployeeno(user.getEmployeeNo().trim());
		if(null == rpy){
			dataSourceTransactionManager.commit(transactionStatus);//提交
			return ResponseMessage.error("登录人工号无OA权限，请联系系统管理员！");
		}

		//分析该访客申请单是否已存在，若已存在给出提示信息。
		ReservationPrimary reservationPrimary_exist=reservationPrimaryMapper.selectOne(
				new QueryWrapper<ReservationPrimary>().eq("RESERVATIONNO",reservationPrimary.getReservationno())
		);
		if(reservationPrimary_exist!=null){
			dataSourceTransactionManager.commit(transactionStatus);//提交
			return ResponseMessage.error("存入访客单失败,该表中已存在该单号!");
		}
		
		///先保存主表
		Date nowDate = new Date();
		reservationPrimary.setCreateUserEmployeeno(user.getEmployeeNo());
		reservationPrimary.setCreateUserDeptno(rpy.getDepartmentcode());
		reservationPrimary.setStatus(1);
		reservationPrimary.setCreateUser(user.getLoginName() + "-" + user.getName());
		reservationPrimary.setCreateTime(nowDate);
		//更新forecastDepartureTime
		Date forecastDepartureTime=DateUtils.addSeconds(reservationPrimary.getForecastDepartureTime(),86399);
		reservationPrimary.setForecastDepartureTime(forecastDepartureTime);
		reservationPrimaryMapper.insert(reservationPrimary);

		/**
		 * 若预约单中含有访客人员信息，存储人员信息。
		 */
		if(!CollectionUtils.isEmpty(reservationPrimary.getReservationList())){
			
			reservationPrimary.getReservationList().forEach(reservation->{
				reservation.setCreateUser(reservationPrimary.getCreateUser());
				reservation.setStatus(1);
				reservation.setEmployeenoPhone(reservationPrimary.getEmployeenoPhone());
				reservation.setEmployeenoReception(reservationPrimary.getEmployeenoReception());
				reservation.setEmployeenameReception(reservationPrimary.getEmployeenameReception());
				reservation.setDeptno(reservationPrimary.getDeptno());
				reservation.setDeptname(reservationPrimary.getDeptname());
				reservation.setForecastVisitingTime(reservationPrimary.getForecastVisitingTime());
				reservation.setForecastDepartureTime(reservationPrimary.getForecastDepartureTime());
				reservation.setDistrictName(reservationPrimary.getDistrictName());
				reservation.setVisitorCompany(reservationPrimary.getVisitorCompany());
				reservation.setVisitingMatters(reservationPrimary.getVisitingMatters());
				reservation.setReservationno(reservationPrimary.getReservationno());
				reservation.setDistrictno(reservationPrimary.getDistrictno());
				reservation.setCompanyno(user.getCompanyno());
				
				String imagePath = PropertyUtil.getImageFileRoot()+reservation.getIdcardno()+".jpg";
				if(saveBase64ToImageFile(reservation.getPhotoBase64(),imagePath)){
					reservation.setIdcardnoUrl(PropertyUtil.getImageUrlRoot()+reservation.getIdcardno()+".jpg");
				}

				reservation.setCreateTime(nowDate);
				reservationMapper.insert(reservation);
			});
		}
		//dataSourceTransactionManager.commit(transactionStatus);//提交
		
		//触发OA流程
		try{
			triggerWorkflow(user,rpy,reservationPrimary);
		}catch (Exception e){
			e.printStackTrace();
			dataSourceTransactionManager.rollback(transactionStatus);
			logger.info("执行了回滚操作!dataSourceTransactionManager.rollback(transactionStatus)..");
			throw e;
		}
		dataSourceTransactionManager.commit(transactionStatus);//提交
		
		logger.info("存入访客预约信息成功! 创建人: "+user.getEmployeeNo());
		return ResponseMessage.ok();
	}

	/**
	 * 创建附件。
	 * @param reservationPrimary
	 * @return
	 */
	public String createAttachment(ReservationPrimary reservationPrimary) {
		if(CollectionUtils.isEmpty(reservationPrimary.getReservationList())){
			return "";
		}

		DocServicePortType service = new DocService().getDocServiceHttpPort();
		String sessionCode = service.login(PropertyUtil.getOaDocUploaderName(), PropertyUtil.getOaDocUploaderPassword(), 0, "127.0.0.1");
		List<String> docIds = new ArrayList<>();
		ByteArrayOutputStream baos = null;

		for (Reservation reservation : reservationPrimary.getReservationList()) {
			if(StringUtils.isBlank(reservation.getIdcardnoUrl())){
				continue;
			}
			DocInfo doc = new DocInfo();
			doc.setDoccontent("");
			doc.setMaincategory(PropertyUtil.getOaDocUploadMaincategory());
			doc.setSubcategory(PropertyUtil.getOaDocUploadSubcategory());
			doc.setSeccategory(PropertyUtil.getOaDocUploadSeccategory());

			ArrayOfDocAttachment attachMents = new ArrayOfDocAttachment();
			DocAttachment da = new DocAttachment();
			String url = reservation.getIdcardnoUrl();
			String fileName = url.substring(url.indexOf("VisitorPhoto")+13);
			da.setImagefilename(fileName.substring(0,fileName.indexOf(".")));
			da.setFilename(fileName);
			doc.setDocSubject("访客预约"+da.getImagefilename());
			try {
				URL u = new URL(url);
				BufferedImage image = ImageIO.read(u);
				baos = new ByteArrayOutputStream();
				ImageIO.write(image, fileName.substring(fileName.indexOf(".")+1), baos);
				baos.flush();

				da.setFilecontent(reservation.getPhotoBase64());
				da.setIszip(1);
				attachMents.getDocAttachment().add(da);
				doc.setAttachments(attachMents);
				int id = service.createDoc(doc, sessionCode);
				if(id>0){
					docIds.add(String.valueOf(id));
				}
			} catch (IOException e) {
				e.printStackTrace();
			} finally {
				if (baos != null) {
					try {
						baos.close();
					} catch (IOException e) {
					}
				}
			}
		}
		return docIds.stream().collect(Collectors.joining(","));
	}

	/**
	 * 触发OA流程，将访客预约单存入OA端。
	 * @param user
	 * @param rpy
	 * @param reservationPrimary
	 * @return
	 */
	public boolean triggerWorkflow(AllowUser user, ReservationPrimary rpy, ReservationPrimary reservationPrimary) {
		//根据是否有照片先创建OA附件
		System.out.println("createAttachment begin: "+System.currentTimeMillis());
		String attachmentIds = createAttachment(reservationPrimary);
		System.out.println("createAttachment end: "+System.currentTimeMillis());
		String workflowId = PropertyUtil.getWorkflowId();
		String creatorId = String.valueOf(rpy.getEmployeeId());
		String requestName = PropertyUtil.getWorkflowName()+user.getName()+"-"+ DateUtils.format(new Date(),"yyyy-MM-dd");

		List<WorkflowFieldInfo> mainDataList = new ArrayList<>();
		mainDataList.add(new WorkflowFieldInfo().fieldName("RESERVATIONNO").fieldValue(reservationPrimary.getReservationno()).canView(true).canEdit(true));
		mainDataList.add(new WorkflowFieldInfo().fieldName("DISTICTNO").fieldValue(reservationPrimary.getDistrictno()).canView(true).canEdit(true));
		mainDataList.add(new WorkflowFieldInfo().fieldName("DISTICTNAME").fieldValue(reservationPrimary.getDistrictName()).canView(true).canEdit(true));
		mainDataList.add(new WorkflowFieldInfo().fieldName("EMPLOYEENAME").fieldValue(reservationPrimary.getEmployeenameReception()).canView(true).canEdit(true));
		mainDataList.add(new WorkflowFieldInfo().fieldName("DEPTNAME").fieldValue(reservationPrimary.getDeptname()).canView(true).canEdit(true));
		mainDataList.add(new WorkflowFieldInfo().fieldName("EMPLOYEENO_PHONE").fieldValue(reservationPrimary.getEmployeenoPhone()).canView(true).canEdit(true));
		mainDataList.add(new WorkflowFieldInfo().fieldName("VISITOR_COMPANY").fieldValue(reservationPrimary.getVisitorCompany()).canView(true).canEdit(true));
		mainDataList.add(new WorkflowFieldInfo().fieldName("FORCAST_VISITING_TIME").fieldValue(DateUtils.format(reservationPrimary.getForecastVisitingTime(),"yyyy-MM-dd hh:mm:ss")).canView(true).canEdit(true));
		mainDataList.add(new WorkflowFieldInfo().fieldName("FORCAST_DEPARTURE_TIME").fieldValue(DateUtils.format(reservationPrimary.getForecastDepartureTime(),"yyyy-MM-dd hh:mm:ss")).canView(true).canEdit(true));
		mainDataList.add(new WorkflowFieldInfo().fieldName("DEPTNO").fieldValue(String.valueOf(rpy.getDepartmentId())).canView(true).canEdit(true));
		mainDataList.add(new WorkflowFieldInfo().fieldName("CREATE_USER").fieldValue(String.valueOf(rpy.getEmployeeId())).canView(true).canEdit(true));
		mainDataList.add(new WorkflowFieldInfo().fieldName("VISTING_MATTERS").fieldValue(reservationPrimary.getVisitingMatters()).canView(true).canEdit(true));
		mainDataList.add(new WorkflowFieldInfo().fieldName("djbh").fieldValue(reservationPrimary.getReservationno()).canView(true).canEdit(true));
		mainDataList.add(new WorkflowFieldInfo().fieldName("qhbmss").fieldValue("").canView(true).canEdit(true));
		mainDataList.add(new WorkflowFieldInfo().fieldName("mainPics").fieldValue(attachmentIds).canView(true).canEdit(true));

		//存入访客成员信息
		List<List<WorkflowFieldInfo>> detailDataList = new ArrayList<>();
		if(!CollectionUtils.isEmpty(reservationPrimary.getReservationList())){
			for(Reservation reservation: reservationPrimary.getReservationList()){
				List<WorkflowFieldInfo> list = new ArrayList<>();
				list.add(new WorkflowFieldInfo().fieldName("VISITOR").fieldValue(reservation.getVisitor()).canView(true).canEdit(true));
				list.add(new WorkflowFieldInfo().fieldName("IDCARDNO").fieldValue(reservation.getIdcardno()).canView(true).canEdit(true));
				list.add(new WorkflowFieldInfo().fieldName("PHONE").fieldValue(reservation.getPhone()).canView(true).canEdit(true));
				list.add(new WorkflowFieldInfo().fieldName("CARRY_ITEMS").fieldValue(reservation.getCarryItems()).canView(true).canEdit(true));
				detailDataList.add(list);
			}
		}

		WorkflowServicePortType workflowService = new WorkflowService().getWorkflowServiceHttpPort();
		System.out.println("doCreateWorkflowRequest begin: "+System.currentTimeMillis());
		Integer requestid = Integer.parseInt(
				workflowService.doCreateWorkflowRequest(
						ecologyWebService.buildWorkflowRequest(workflowId,creatorId,"0",requestName,mainDataList,detailDataList),
						rpy.getEmployeeId()));
		System.out.println("doCreateWorkflowRequest end: "+System.currentTimeMillis());

		if(requestid>0) return true;
		return false;
	}

	//对字节数组字符串进行Base64解码并生成图片
	private boolean saveBase64ToImageFile(String imgStr, String imagePath) {
		if (imgStr == null) //图像数据为空
			return false;
		BASE64Decoder decoder = new BASE64Decoder();
		try {
			//Base64解码
			byte[] b = decoder.decodeBuffer(imgStr);
			for (int i = 0; i < b.length; ++i) {
				if (b[i] < 0) {//调整异常数据
					b[i] += 256;
				}
			}
			//生成jpeg图片
			OutputStream out = new FileOutputStream(imagePath);
			out.write(b);
			out.flush();
			out.close();
			return true;
		} catch (Exception e) {
			logger.error("将base64格式的字符串编码,并存入对应的图片文件中，发生错误!"+e.toString());
			return false;
		}
	}

	private ReservationPrimary getByCreateUserEmployeeno(String workcode) {
		return reservationPrimaryMapper.findByCreateUserEmployeeno(workcode);
	}
	
	/**
	 * 存入访客预约信息(reservationPrimary)，并将该预约信息提交至泛微OA端。
	 * <br>将"预约信息存入泛微OA端比较耗时"(需要20s)，此处使用了"异步任务"。
	 * @deprecated 待删_bycjw
	 * @param
	 * @return
	 * @author cjw 2019-12-19
	 */
	@Deprecated
	public ResponseMessage saveReservationPrimary(AllowUser user, ReservationPrimary reservationPrimary) {

		/**
		 * 验证该用户是否有OA办公权限。
		 */
		ReservationPrimary rpy = getByCreateUserEmployeeno(user.getEmployeeNo().trim());
		if(null == rpy){
			return ResponseMessage.error("登录人工号无OA权限，请联系系统管理员！");
		}

		//分析该访客申请单是否已存在，若已存在给出提示信息。
		ReservationPrimary reservationPrimary_exist=reservationPrimaryMapper.selectOne(
				new QueryWrapper<ReservationPrimary>().eq("RESERVATIONNO",reservationPrimary.getReservationno())
		);
		if(reservationPrimary_exist!=null){
			return ResponseMessage.error("存入访客单失败,该表中已存在该单号!");
		}

		/**
		 * 存入ReservationPrimary信息。
		 */
		Date nowDate = new Date();
		reservationPrimary.setCreateUserEmployeeno(user.getEmployeeNo());
		reservationPrimary.setCreateUserDeptno(rpy.getDepartmentcode());
		reservationPrimary.setStatus(1);
		reservationPrimary.setCreateUser(user.getLoginName() + "-" + user.getName());
		reservationPrimary.setCreateTime(nowDate);
		reservationPrimaryMapper.insert(reservationPrimary);

		//若预约单中含有访客人员信息，存储人员信息。
		if(!CollectionUtils.isEmpty(reservationPrimary.getReservationList())){
			reservationPrimary.getReservationList().forEach(reservation->{
				reservation.setCreateUser(reservationPrimary.getCreateUser());
				reservation.setStatus(1);
				reservation.setEmployeenoPhone(reservationPrimary.getEmployeenoPhone());
				reservation.setEmployeenoReception(reservationPrimary.getEmployeenoReception());
				reservation.setEmployeenameReception(reservationPrimary.getEmployeenameReception());
				reservation.setDeptno(reservationPrimary.getDeptno());
				reservation.setDeptname(reservationPrimary.getDeptname());
				reservation.setForecastVisitingTime(reservationPrimary.getForecastVisitingTime());
				reservation.setForecastDepartureTime(DateUtils.addSeconds(reservationPrimary.getForecastDepartureTime(),86399));
				reservation.setDistrictName(reservationPrimary.getDistrictName());
				reservation.setVisitorCompany(reservationPrimary.getVisitorCompany());
				reservation.setVisitingMatters(reservationPrimary.getVisitingMatters());
				reservation.setReservationno(reservationPrimary.getReservationno());
				reservation.setDistrictno(reservationPrimary.getDistrictno());
				reservation.setCompanyno(user.getCompanyno());
				//存入访客人员的身份证图片
				String imagePath = PropertyUtil.getImageFileRoot()+reservation.getIdcardno()+".jpg";
				if(saveBase64ToImageFile(reservation.getPhotoBase64(),imagePath)){
					reservation.setIdcardnoUrl(PropertyUtil.getImageUrlRoot()+reservation.getIdcardno()+".jpg");
				}
				reservation.setCreateTime(nowDate);
				reservationMapper.insert(reservation);
			});
		}

		/**
		 * 将该访客预约单，提交至OA端。
		 */
		AsyncTask_submitReservationPrimary_toOA.getInstance().submitAsyncTask(user,rpy,reservationPrimary);

		logger.info("存入访客预约信息成功! 创建人为"+user.getEmployeeNo());
		return ResponseMessage.ok();
	}
	
	/**
	 * 将访客预约单提交至OA端。
	 * <br>该方法可供异步任务调用。
	 * @deprecated 待删_bycjw
	 * @param
	 * @return
	 * @author cjw 2019-12-25
	 */
	@Deprecated
	public String submitReservationPrimary_toOA(AllowUser allowUser, ReservationPrimary rpy, ReservationPrimary reservationPrimary){

		//将访客预约单提交至OA端。
		try{
			triggerWorkflow(allowUser, rpy, reservationPrimary);
			return Constants.SUCCESS;
		}catch (Exception e){
			e.printStackTrace();
			logger.error("将访客预约单["+reservationPrimary.getReservationno()+"]存入OA端，出错!"+e.toString());
		}
		return Constants.ERROR;
	}



}
